package com.hup.winHolderService.framework.exception;

import com.hup.winHolderService.framework.model.ExceptionResult.BaseResultException;
import com.hup.winHolderService.framework.util.net.HttpUtil;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;

import javax.servlet.http.HttpServletRequest;

/**
 * msg=请求异常
 * 不给用户看的异常,处理非正常请求
 * {@link HttpStatus#BAD_REQUEST}
 *
 * @author hugan
 * @date 2023/7/9
 */
@Slf4j
public class AppHiddenMsgException extends RuntimeException implements BaseResultException {

    @Getter
    private HttpStatus status = HttpStatus.BAD_REQUEST;

    public AppHiddenMsgException(String message) {
        super(message);
    }

    public AppHiddenMsgException(String message, Throwable e) {
        super(message, e);
    }

    @Override
    public String getRespMessage() {
        return "请求异常";
    }

    @Override
    public void doLog() {
        HttpServletRequest request = HttpUtil.getRequest();
        String ipAddr = HttpUtil.getIpAddr(request);
        log.error(AppLogger.getStack("ip=" + ipAddr + ", " + getMessage(), getCause() == null ? this : getCause()));
    }

}
